//
//  CustomAnnotationView.swift
//  ERecycle-Shop
//
//  Created by abb on 16/8/15.
//  Copyright © 2016年 abb. All rights reserved.
//

import UIKit

class CustomAnnotationView: MAAnnotationView {
    override func setSelected(selected: Bool, animated: Bool) {
        if self.selected == selected {
            return
        }
        if selected {
            calloutView.image = UIImage(named: "pin_select")
            calloutView.center = CGPoint(x: CGRectGetWidth(self.bounds) / 2 + calloutOffset.x, y: CGRectGetHeight(self.bounds) / 2 + self.calloutOffset.y)
            calloutView.transform = CGAffineTransformMakeScale(1.0, 0)
            calloutView.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
            addSubview(calloutView)
            UIView.animateWithDuration(0.5, animations: {
                self.calloutView.transform = CGAffineTransformIdentity
                })
        } else {

            self.calloutView.removeFromSuperview()
            
        }
        super.setSelected(selected, animated: animated)
    }
    
    private lazy var calloutView:CustomCalloutView = CustomCalloutView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
}
